package com.tamecode.chapter06.sec45;

import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.GregorianCalendar;
import java.util.Locale;

/**
 * @Author: Qiongchao
 * @Version: 1.0.0
 * @Date: 2023/9/27
 */
public class ReloadResBundleMsgStarter {
    public static void main(String[] args) throws InterruptedException {
        String[] configs = {"sec6-45/i18n/beans-ReloadResBundle.xml"};
        ApplicationContext ctx = new ClassPathXmlApplicationContext(configs);
        MessageSource ms = (MessageSource)ctx.getBean("myResource");
        Object[] params = {"John", new GregorianCalendar().getTime()};
        for (int i = 0; i < 2; i++) {
            String str1 = ms.getMessage("greeting.common",params,Locale.US);
            System.out.println(str1);
            // 模拟程序应用，在此期间，更改资源文件
            // 可以看到两次输出的格式化信息分别对应更改前后的内容，即本地化资源文件的调整自动生效了。
            /*
            -- How are you!John,today is 9/27/23 10:55 PM --
            How are you!John,today is 9/27/23 10:55 PM
             */
            Thread.currentThread().sleep(10000);
        }
    }
}
